#include <bits/stdc++.h>
using namespace std;
struct car{
    int d,v,a,ql,qr;
    bool ch,tch;
    car(bool ccc=false,bool ttt=false){
        ch=ccc;
        tch=ttt;
    }
}cars[100100];
vector<car> v;
bool cv[1000100];
int n,m,ml,mv,tosort;
bool cmp(car c1,car c2){
    return c1.ql<c2.ql;
}
bool cmp2(car c1,car c2){
    if(c1.qr<tosort) return false;
    if(c2.qr<tosort) return true;
    return c1.ql<c2.ql;
}
bool cmp3(car c1,car c2){
    return c1.qr<c2.qr;
}
vector<car> q;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t,i,j;
    scanf("%d",&t);
    while(t>0){
        int x;
        t--;
        memset(cv,0,sizeof(cv));
        scanf("%d %d %d %d",&n,&m,&ml,&mv);
        for(i=1;i<=n;i++){
            scanf("%d %d %d",&cars[i].d,&cars[i].v,&cars[i].a);
            if(cars[i].v>mv){
                cars[i].ch=true;
                cars[i].ql=cars[i].d;
                if(cars[i].a>=0) cars[i].qr=ml;
                else{
                    int kkk=(double)((mv*mv)-(cars[i].v*cars[i].v)+1)/(2*cars[i].a);
                    cars[i].qr=min(cars[i].d+kkk,ml);
                }
            }
            if(cars[i].v<=mv){
                cars[i].ch=false;
                cars[i].ql=cars[i].qr=ml+1;
                if(cars[i].a>0){
                    int kkk=(double)((mv*mv)-(cars[i].v*cars[i].v))/(2*cars[i].a)+1;
                    if(cars[i].d+kkk<=ml){
                        cars[i].ql=cars[i].d+kkk;
                        cars[i].qr=ml;
                        cars[i].ch=true;
                    }
                    else{
                        cars[i].ql=ml+1;
                    }
                }
            }
        }
        for(i=1;i<=m;i++){
            scanf("%d",&x);
            cv[x]=true;
        }
        int idx=0,tol=0,tol2=0;
        sort(cars+1,cars+n+1,cmp);
        for(i=1;i<=ml;i++){
            while(idx<n&&cars[idx+1].ch&&cars[idx+1].ql<=i){
                ++idx;
                q.push_back(cars[idx]);
            }
            if(cv[i]){
                tosort=i;
                sort(q.begin(),q.end(),cmp2);
                while(q.size()>0&&q[q.size()-1].qr<i){
                    q.pop_back();
                }
                while(q.size()>0){
                    j=q.size()-1;
                    q[j].tch=true;
                    tol++;
                    v.push_back(q[j]);
                    q.pop_back();
                }
            }
        }
        sort(v.begin(),v.end(),cmp3);
        while(q.size()>0) q.pop_back();
        i=0;
        int p=-1;
        while(i<v.size()){
            if(v[i].ql<=p){
                i++;
                continue;
            }
            j=v[i].qr;
            while(j>=v[i].ql&&!cv[j]) j--;
            tol2++;
            p=j;
            i++;
        }
        printf("%d %d\n",tol,m-tol2);
        while(v.size()>0) v.pop_back();
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
